<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
		<p>
			用户名：
			<input type="text" value="" />
		</p>
		<p>
			用户名：
			<input type="password" value="" />
		</p>
		<p>
			<input type="button" class=" btn" value="登录" />
		</p>
	</body>
	<script type="text/javascript">
		var inputs = document.querySelectorAll("input");
		inputs[2].onclick = function(){
			var username = inputs[0].value;
			var password = inputs[1].value;
			
		}
		
		function ajax(){
			var xhr = new XMLHttpRequest();
			xhr.onreadystatechange = function(){
				if(xhr.readyState ==4){
					console.log(xhr.responseText)
				}
			}
			xhr.open("POST","http://47.95.123.51:8080/tjj/sso/oauth2/access_token")
			var data = {
				"username":"admin",
				"password":"123456",
				"grant_type":'password',
				"client_id":'cloud-upms',
				"client_secret":'cloud-upms'
			};
			var params = formatParams(data);
			xhr.setRequestHeader("content-type","application/x-www-form-urlencoded")
			xhr.send(params)
			
		}
		
				    //格式化请求参数
    function formatParams(data){
        var arr=[];
		for(var item in data){
			arr.push(item+"="+data[item])
		}
		return	arr.join("&")
    }
		
	ajax()
		
	</script>
</html>
